﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Facade;
using IronOne.SalesOne.BusinessObjects;

namespace IronOne.SalesOne.SalesOneWeb.ContactManagement
{
    public partial class ShowPolicies : SOSecurityPage, IDataPage, IntTest
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                string id = string.Empty;
                if (!IsPostBack)
                {
                    if (!string.IsNullOrEmpty(Request.QueryString["cl"]))
                    {
                        id = Request.QueryString["cl"];

                        if (Session["so"] != null)
                        {
                            string so = Session["so"].ToString();
                            CustomerFacade cFac = new CustomerFacade();
                            List<Policy> resPolicy = cFac.GetPoliciesForClient(id, so);

                            if (resPolicy.Count > 0)
                            {
                                UCGrid1.styleList = new List<GridViewStyle> {
                                new GridViewStyle{
                                    ColumnId = "CustomerId",
                                    ColumnHeader = "Client Id",
                                    ColumnWidth = 130 },
                                new GridViewStyle{
                                    ColumnId = "ContractId",
                                    ColumnHeader = "Policy No",
                                    ColumnWidth = 130},                
                                new GridViewStyle{
                                    ColumnId = "PlanCode",
                                    ColumnHeader = "Plan CD",
                                    ColumnWidth = 100},
                                    new GridViewStyle{
                                    ColumnId = "DueDate",
                                    ColumnHeader = "Due Date",
                                    ColumnWidth = 130},
                               new GridViewStyle{
                                    ColumnId = "PolicyState",
                                    ColumnHeader = "Policy Status",
                                    ColumnWidth = 130},
                               new GridViewStyle{
                                    ColumnId = "Premium",
                                    ColumnHeader = "Premium(Rs)",
                                    Align = "right",
                                    ColumnWidth = 130},
                               new GridViewStyle{
                                    ColumnId = "CollectionDue",
                                    ColumnHeader = "Collection Due(Rs)",
                                    Align = "right",
                                    ColumnWidth = 130},
                               new GridViewStyle{
                                    ColumnId = "LastUpdatedDate",
                                    ColumnHeader = "Last Updated Timestamp",
                                    ColumnWidth = 130}
                                
                            };
                                //int[] hideNo = { 1, 5, 6, 8, 9, 10, 13, 14, 15, 18 };
                                int[] hideNo = { 1, 11, 12, 13, 14, 15, 16, 17, 18 };
                                UCGrid1.SetDataSource(resPolicy, hideNo);

                                UCGridButtons1.SetCredentials(ValidateUserCredentials(Request.Url.LocalPath));
                            }

                            //Session.Remove("so");

                        }


                    }
                }
            }
            catch (Exception)
            {

            }

        }





        #region IDataPage Members

        public void Create()
        {

        }

        public void View()
        {
            try
            {
                if (Session["cont"] == null)
                {
                    if (Session["firstRow"] != null)
                    {
                        Session["cont"] = ((GridViewRow)Session["firstRow"]).Cells[2].Text;
                        Session.Remove("firstRow"); 
                    }
                    else
                    {
                        MassageSummery("IIS502");
                    }
                    
                }


                if (Session["cont"] != null)
                {
                    Response.Redirect("~/ContactManagement/PolicyDetails.aspx?con=" + Session["cont"].ToString() + "&t=c");
                    Session.Remove("cont");
                }
            }
            catch (Exception)
            {
                

            }
           
        }

        public void Update()
        {

        }

        public void Delete()
        {

        }

        public void Cancel()
        {

        }

        public void GetId(GridViewRow row)
        {
            Session["cont"] = row.Cells[2].Text;
        }

        #endregion

        #region IntTest Members

        public void Next()
        {
            //if (UCGrid1.GetText() != "1")
            //{
            //    pageNo = Convert.ToInt32(UCGrid1.GetText()) + 1;
            //    UCGrid1.SetText(pageNo.ToString());

            //}
            //else
            //{
            //    pageNo = 2;
            //    UCGrid1.SetText("2");

            //}

            //Search(string.Empty, pageNo);
        }

        public void Previous()
        {

        }

        public void Go()
        {

        }

        #endregion

        protected void btnCancel_Click(object sender, EventArgs e)
        {
            try
            {
                if (!string.IsNullOrEmpty(Request.QueryString["cl"]))
                {
                    string cl = Request.QueryString["cl"].ToString();
                    CustomerFacade cFac = new CustomerFacade();
                    Customer c = cFac.GetCustomer(cl);
                    Session["client"] = c;
                    Response.Redirect("~/ContactManagement/ClientDetails.aspx?t=p");
                }
            }
            catch (Exception)
            {

            }
            
        }
    }
}
